﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HZ.Supervise.DAL
{
    public class DAL_WarningData
    {
        public static System.Data.DataTable GetInvoiceNoPay(HZ.Supervise.Model.Query.mQuery query,int WarningDate, int currentpage, int pagesize, out int totalrecord)
        {
            string wherestr = DAL_Helper.GetWhereCondition(query, false);
            StringBuilder sql = new StringBuilder();
            sql.Append(string.Format("select * from dbo.View_InvoiceDistribution where WarehouseCount > 0 AND IsInvoice = 1 and AuditStatus = '1'and InvoicePaySerialID IS NULL and WarehouseTime<='" + System.DateTime.Now.AddDays(-1 * WarningDate) + "' {0} order by {1}", wherestr, query.SortFields));
            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;
            return des.GetSpecailPage();
        }
        public static System.Data.DataTable GetComNoConfimInvoicePay(HZ.Supervise.Model.Query.mQuery query, int WarningDate, int currentpage, int pagesize, out int totalrecord)
        {
            string wherestr = DAL_Helper.GetWhereCondition(query, false);
            StringBuilder sql = new StringBuilder();
            sql.Append(string.Format("select * from dbo.View_InvoicePay where PayStatus = 0 and InvoicePayTime<='" + System.DateTime.Now.AddDays(-1 * WarningDate) + "'{0} order by {1}", wherestr, query.SortFields));
            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;
            return des.GetSpecailPage();
        }
        public static System.Data.DataTable GetComNoConfimReturnOrder(HZ.Supervise.Model.Query.mQuery query, int WarningDate, int currentpage, int pagesize, out int totalrecord)
        {
            string wherestr = DAL_Helper.GetWhereCondition(query, false);
            StringBuilder sql = new StringBuilder();
            sql.Append(string.Format("select * from dbo.View_ReturnMerchandiseDetail where ReturnOrderStatus = 2 AND ReturnState = 0 and ReturnTime<='" + System.DateTime.Now.AddDays(-1 * WarningDate) + "'{0} order by {1}",wherestr, query.SortFields));
            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;
            return des.GetSpecailPage();
        }
        public static System.Data.DataTable GetInvoiceNoCheck(HZ.Supervise.Model.Query.mQuery query, int WarningDate, int currentpage, int pagesize, out int totalrecord)
        {
            string wherestr = DAL_Helper.GetWhereCondition(query, false);
            StringBuilder sql = new StringBuilder();
            sql.Append(string.Format("select * from dbo.View_Invoice where IsSubmit = 1 AND AuditStatus = 0 and AddDate<='" + System.DateTime.Now.AddDays(-1 * WarningDate) + "' {0} order by {1}", wherestr, query.SortFields));
            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;
            return des.GetSpecailPage();
        }
        public static System.Data.DataTable GetHospitalNoStock(HZ.Supervise.Model.Query.mQuery query, int WarningDate, int currentpage, int pagesize, out int totalrecord)
        {
            string wherestr = DAL_Helper.GetWhereCondition(query, false);
            StringBuilder sql = new StringBuilder();
            sql.Append(string.Format("select * from dbo.View_Distribution where DistributeState=0 and WarehouseTime IS NULL AND DistributeTime<='" + System.DateTime.Now.AddDays(-1 * WarningDate) + "' {0} order by {1}", wherestr, query.SortFields));
            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;
            return des.GetSpecailPage();
        }
        public static System.Data.DataTable GetOrderNoConfim(HZ.Supervise.Model.Query.mQuery query, int WarningDate, int currentpage, int pagesize, out int totalrecord)
        {
            string wherestr = DAL_Helper.GetWhereCondition(query, false);
            StringBuilder sql = new StringBuilder();
            sql.Append(string.Format("select * from dbo.View_PurchaseOrderDetail where OrderDetailState=1 and StartTime<='" + System.DateTime.Now.AddDays(-1 * WarningDate) + "'{0} order by {1}", wherestr, query.SortFields));
            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;
            return des.GetSpecailPage();
        }
        public static System.Data.DataTable GetOrderOverWarning(HZ.Supervise.Model.Query.mQuery query, int WarningDate, int WarningCount, decimal WarningAmount, int currentpage, int pagesize, out int totalrecord)
        {
            string wherestr = DAL_Helper.GetWhereCondition(query, false);
            StringBuilder sql = new StringBuilder();
            sql.Append(string.Format("select * from dbo.View_PurchaseOrderDetail where PlanTime<='" + System.DateTime.Now.AddDays(-1 * WarningDate) + "'and (PurchaseCount > ' "+ WarningCount +" ' or Amount > '" + WarningAmount +" '){0} order by {1}", wherestr, query.SortFields));
            HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
            des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;
            return des.GetSpecailPage();
        }
    }
}
